package com.fare.taluo.application.impl.analyse;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.ListUtils;

import com.fare.taluo.util.DateUtils;
import com.fare.taluo.vo.core.PlaneInfo;

/**
 * @author spring.华 
 * 	e-mail 13719279477@139.com
 */
public enum ChoseEnum {
	
	M{//上午
		public List<PlaneInfo> getPlaneInfos(List<String> dates,String rowKeyHead) throws Exception{
			return this.implPlaneChoseData(dates,rowKeyHead,"08","12");
		}
		public List<PlaneInfo> getPlaneInfos(String tablename,List<String> dates,String rowKeyHead) throws Exception{
			return this.implPlaneChoseData(tablename,dates,rowKeyHead,"08","12");
		}
	},
	B{//中午
		public List<PlaneInfo> getPlaneInfos(List<String> dates,String rowKeyHead) throws Exception{
			return this.implPlaneChoseData(dates,rowKeyHead,"12","14");
		}
		public List<PlaneInfo> getPlaneInfos(String tablename,List<String> dates,String rowKeyHead) throws Exception{
			return this.implPlaneChoseData(tablename,dates,rowKeyHead,"12","14");
		}
	},
	A{//下午
		public List<PlaneInfo> getPlaneInfos(List<String> dates,String rowKeyHead) throws Exception{
			return this.implPlaneChoseData(dates,rowKeyHead,"14","18");
		}
		public List<PlaneInfo> getPlaneInfos(String tablename,List<String> dates,String rowKeyHead) throws Exception{
			return this.implPlaneChoseData(tablename,dates,rowKeyHead,"14","18");
		}
	},
	N{//nihgt
		public List<PlaneInfo> getPlaneInfos(List<String> dates,String rowKeyHead) throws Exception{
			List<PlaneInfo> list1=this.implPlaneChoseData(dates,rowKeyHead,"18","24");
			List<PlaneInfo> list2=this.implPlaneChoseData(dates,rowKeyHead,"00","08");
			return ListUtils.sum(list1, list2);//合并
		}
		public List<PlaneInfo> getPlaneInfos(String tablename,List<String> dates,String rowKeyHead) throws Exception{
			List<PlaneInfo> list1=this.implPlaneChoseData(tablename,dates,rowKeyHead,"18","24");
			List<PlaneInfo> list2=this.implPlaneChoseData(tablename,dates,rowKeyHead,"00","08");
			return ListUtils.sum(list1, list2);//合并
		}
	},
	P{//自定义时间
		public List<PlaneInfo> getPlaneInfos(List<String> dates,String rowKeyHead,String timeBegin,String timeEnd)throws Exception{
				return this.implPlaneChoseData(dates,rowKeyHead,timeBegin,timeEnd);
		}
		public List<PlaneInfo> getPlaneInfos(String tablename,List<String> dates,String rowKeyHead,String timeBegin,String timeEnd)throws Exception{
			return this.implPlaneChoseData(tablename,dates,rowKeyHead,timeBegin,timeEnd);
		}
	}
	;
	
	public List<PlaneInfo> getPlaneInfos(List<String> dates,String rowKeyHead)throws Exception{
		
		return null;
	}
	public List<PlaneInfo> getPlaneInfos(List<String> dates,String rowKeyHead,String timeBegin,String timeEnd)throws Exception{
		
		return null;
	}
	//table
	public List<PlaneInfo> getPlaneInfos(String tableName,List<String> dates,String rowKeyHead,String timeBegin,String timeEnd)throws Exception{
		
		return null;
	}//
	public List<PlaneInfo> getPlaneInfos(String tableName,List<String> dates,String rowKeyHead)throws Exception{
			
		return null;
	}
	
	@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
	protected  List<PlaneInfo>  implPlaneChoseData(List<String> dates,String rowKeyHead,String beginTime,String endTime) throws Exception{
		ChannelContrastApplicationImpl impl=new ChannelContrastApplicationImpl(); 
		List<List<PlaneInfo>>  dataList=new ArrayList();
		for (Iterator iterator = dates.iterator(); iterator.hasNext();) {
			String date = (String) iterator.next();
			if(beginTime.equals("00")){//晚上零时加一天
				dataList.add(impl.earchChannelContrast(rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyyMMdd")+beginTime,
						rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyyMMdd")+endTime,null));
			}else{
				dataList.add(impl.earchChannelContrast(rowKeyHead+DateUtils.getPageDateStr(date, "yyyyMMdd")+beginTime, rowKeyHead+DateUtils.getPageDateStr(date, "yyyyMMdd")+endTime,null));
			}
			
		}
		List<PlaneInfo> list=new ArrayList<PlaneInfo>();
		for (Iterator iterator = dataList.iterator(); iterator.hasNext();) {
			List<PlaneInfo> pls = (List<PlaneInfo>) iterator.next();
			for (Iterator iterator2 = pls.iterator(); iterator2.hasNext();) {
				PlaneInfo planeInfo = (PlaneInfo) iterator2.next();
				if(planeInfo!=null){
					list.add(planeInfo);
				}
			}
			
		}
		return list;
		
	}
	
	@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
	protected  List<PlaneInfo>  implPlaneChoseData(String tablename,List<String> dates,String rowKeyHead,String beginTime,String endTime) throws Exception{
		   String START_FLIGHT_NO = "000000000000000000000000";
		   String END_FLIGHT_NO = "ZZZZZZZZZZZZZZZZZZZZZZZZ";
		ChannelContrastApplicationImpl impl=new ChannelContrastApplicationImpl(); 
		List<List<PlaneInfo>>  dataList=new ArrayList();
		for (Iterator iterator = dates.iterator(); iterator.hasNext();) {
			String date = (String) iterator.next();
			
			if(beginTime.equals("00")){//晚上零时加一天
				//判断是不是查询LP_FLIGHT_DATE
				if(tablename.indexOf("LP_FLIGHT_DATE")!=-1){
					String startRowKey = rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyy-MM-dd").replace("-", "")+START_FLIGHT_NO;
					String endRowKey = rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyy-MM-dd").replace("-", "")+END_FLIGHT_NO;	
					dataList.add(impl.searchByHbaseRowModel(tablename, startRowKey, endRowKey, null));
				}else if("LP_FLIGHT_DOUBLE".equals(tablename)){
					// xiechengHead = "00003"+toCode+arrCode+"-"+vo.getReturnDate();
					//渠道(5)_起点(使用三字码)(3)_终点(使用三字码)(3)_航班日期(年月日)(8)_返程日期(年月日)(8)_(航班号)(8)
					String returnDate = rowKeyHead.split("-")[1];
					String startRowKey = rowKeyHead.replace("-", DateUtils.getNextDateByDateStr(date, "yyyy-MM-dd").replace("-", ""))+START_FLIGHT_NO;
					String endRowKey = rowKeyHead.replace("-", DateUtils.getNextDateByDateStr(date, "yyyy-MM-dd").replace("-", ""))+END_FLIGHT_NO;
					dataList.add(impl.searchByHbaseRowModel(tablename, startRowKey, endRowKey, null));
				}else {
					dataList.add(impl.searchByHbaseRowModel(tablename, rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyy-MM-dd").replace("-", "")+beginTime, rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyy-MM-dd").replace("-", "")+endTime, null));
				}
				
			}else{
				//判断是不是查询LP_FLIGHT_DATE
				if(tablename.indexOf("LP_FLIGHT_DATE")!=-1){
					String startRowKey = rowKeyHead+date.replace("-", "")+START_FLIGHT_NO;
					String endRowKey = rowKeyHead+date.replace("-", "")+END_FLIGHT_NO;	
					dataList.add(impl.searchByHbaseRowModel(tablename, startRowKey, endRowKey, null));
				}else if("LP_FLIGHT_DOUBLE".equals(tablename)){
					// xiechengHead = "00003"+toCode+arrCode+"-"+vo.getReturnDate();
					//渠道(5)_起点(使用三字码)(3)_终点(使用三字码)(3)_航班日期(年月日)(8)_返程日期(年月日)(8)_(航班号)(8)
					String returnDate = rowKeyHead.split("-")[1];
					//String startRowKey = rowKeyHead+date.replace("-", "")+returnDate+START_FLIGHT_NO;
					//String endRowKey = rowKeyHead+date.replace("-", "")+returnDate+END_FLIGHT_NO;
					String startRowKey = rowKeyHead.replace("-", date.replace("-", ""))+START_FLIGHT_NO;
					String endRowKey = rowKeyHead.replace("-", date.replace("-", ""))+END_FLIGHT_NO;
					dataList.add(impl.searchByHbaseRowModel(tablename, startRowKey, endRowKey, null));
				}/*else {
					
					dataList.add(impl.searchByHbaseRowModel(tablename,rowKeyHead+DateUtils.getPageDateStr(date, "yyyyMMdd")+beginTime, rowKeyHead+DateUtils.getPageDateStr(date, "yyyyMMdd")+endTime,null));
				}*/
			}
			
		}
		List<PlaneInfo> list=new ArrayList<PlaneInfo>();
		for (Iterator iterator = dataList.iterator(); iterator.hasNext();) {
			List<PlaneInfo> pls = (List<PlaneInfo>) iterator.next();
			for (Iterator iterator2 = pls.iterator(); iterator2.hasNext();) {
				PlaneInfo planeInfo = (PlaneInfo) iterator2.next();
				if(planeInfo!=null){
					list.add(planeInfo);
				}
			}
			
		}
		return list;
		
	}
	
}
